<!DOCTYPE html>
<html xmlns:th="http://www.springframework.org/schema/jdbc">
<head>
    <meta charset="utf-8">
    <title>添加设备</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Name" name="Name" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">设备编号</label>
                    <div class="layui-input-inline">
                        <input type="text" id="DeviceID" name="DeviceID" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <span>设备编号通过获取设备信息参看，具有唯一性</span>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">描述</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Version" name="Version" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">设备IP</label>
                    <div class="layui-input-inline">
                        <input type="text" id="IPAddr" name="IPAddr" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">掩码</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Submask" name="Submask" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">网关</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Gateway" name="Gateway" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">服务器端口</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Listenport" name="Listenport" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-inline">
                    <label class="layui-form-label required">Web端口</label>
                    <div class="layui-input-inline">
                        <input type="text" id="Webport" name="Webport" lay-verify="required" value="" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                    <button type="button" class="layui-btn layui-btn-primary l" onclick="back()">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script th:inline="javascript">
    layui.use(['form'], function () {
        let form = layui.form
            , layer = layui.layer
            , $ = layui.$;

        $(document).ready(function () {
            let device = [[${device}]];

            console.log(device);
            if (device !==null){
                $("#Name").val(device.name);
                $('#DeviceID').val(device.deviceID);
                $('#Version').val(device.version);
                $('#IPAddr').val(device.ipaddr);
                $('#Submask').val(device.submask);
                $('#Gateway').val(device.gateway);
                $('#Listenport').val(device.listenport);
                $('#Webport').val(device.webport);
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url:`/addDevice`,
                type:`post`,
                dataType:`json`,
                data: data.field,
                success:function (res) {
                    console.log(res);
                    if (res.code == 200){
                        layer.msg('添加成功');
                        // let index = parent.layer.getFrameIndex(window.name);
                        // parent.layer.close(index);//关闭当前页
                        layer.close(layer.index);
                        window.parent.location.reload();
                    }else{
                        layer.msg('添加失败');
                    }
                }
            });
            return false;
        });

        window.back = function () {
            let iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        }
    });
</script>
</body>
</html>